package com.yihusitian.zsxq.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yihusitian.zsxq.mapper.UserMapper;
import com.yihusitian.zsxq.pojo.data.UserDO;
import com.yihusitian.zsxq.pojo.dto.Owner;
import com.yihusitian.zsxq.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @Description TODO
 * @Author LeeHo
 * @Date 2021-03-25 11:49:28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {

    @Override
    public UserDO createOrUpdate(Owner owner) {
        if (owner == null) {
            return null;
        }
        UserDO oldUserDO = getById(owner.getUser_id());
        if (oldUserDO != null) {
            return oldUserDO;
        }
        UserDO userDO = UserDO.builder().id(owner.getUser_id()).avatarUrl(owner.getAvatar_url()).description(owner.getDescription()).name(owner.getName()).build();
        userDO.insert();
        return userDO;
    }
}